//
//  RootViewController.m
//  多玩盒子
//
//  Created by 刘胜 on 16/2/24.
//  Copyright © 2016年 刘胜. All rights reserved.
//

#import "RootViewController.h"
#import "SaiViewController.h"
#import "VideoViewController.h"
#import "TopViewController.h"
#import "PicViewController.h"
#import "PhotoViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#define WID [[UIScreen mainScreen] bounds].size.width / 375
#define HEI [[UIScreen mainScreen] bounds].size.height / 667

@interface RootViewController ()<UIScrollViewDelegate>

@property(nonatomic,strong)UIScrollView * bigScrollView;
@property(nonatomic,retain)UIView *sliderView;


@end

@implementation RootViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"咨讯";
    [self creatScrollView];
    [self creatButton];
    [self creatSliderView];
}
-(void)creatSliderView {
    self.sliderView = [[UIView alloc] initWithFrame:CGRectMake(self.topButton.frame.origin.x, self.topButton.frame.origin.y+self.topButton.frame.size.height, self.topButton.frame.size.width, 2)];
    self.sliderView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:self.sliderView];
}
-(void)creatButton {
    self.topButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.topButton.frame = CGRectMake(0, 64, WIDTH/5, 40);
    [self.topButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.topButton setTitle:@"头条" forState:UIControlStateNormal];
    self.topButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.view addSubview:self.topButton];
    [self.topButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.videoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.videoButton.frame = CGRectMake(self.topButton.frame.origin.x+self.topButton.frame.size.width, 64, WIDTH/5, self.topButton.frame.size.height);
    [self.videoButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.videoButton setTitle:@"视频" forState:UIControlStateNormal];
    self.videoButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.view addSubview:self.videoButton];
    [self.videoButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.saishiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.saishiButton.frame =CGRectMake(self.videoButton.frame.origin.x+self.videoButton.frame.size.width, 64, WIDTH/5, self.topButton.frame.size.height);
    [self.saishiButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.saishiButton setTitle:@"赛事" forState:UIControlStateNormal];
    self.saishiButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.saishiButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.saishiButton];
    
    self.picButtonn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.picButtonn.frame = CGRectMake(self.saishiButton.frame.origin.x+self.saishiButton.frame.size.width, 64, WIDTH/5, self.topButton.frame.size.height);
    [self.picButtonn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.picButtonn setTitle:@"靓照" forState:UIControlStateNormal];
    self.picButtonn.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.view addSubview:self.picButtonn];
    [self.picButtonn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.phtotButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.phtotButton.frame = CGRectMake(self.picButtonn.frame.origin.x+self.picButtonn.frame.size.width, 64, WIDTH/5, self.topButton.frame.size.height);    [self.phtotButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [self.phtotButton setTitle:@"壁纸" forState:UIControlStateNormal];
    self.phtotButton.titleLabel.font = [UIFont systemFontOfSize:15 weight:0];
    [self.view addSubview:self.phtotButton];
    [self.phtotButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

-(void)buttonAction:(UIButton *)btn
{
    if (btn == self.topButton) {
        [self.bigScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }else if(btn == self.videoButton) {
        [self.bigScrollView setContentOffset:CGPointMake(WIDTH, 0) animated:YES];
    }else if(btn == self.saishiButton) {
        [self.bigScrollView setContentOffset:CGPointMake(WIDTH*2, 0) animated:YES];
    }else if (btn == self.picButtonn) {
        [self.bigScrollView setContentOffset:CGPointMake(WIDTH*3, 0) animated:YES];
    }else {
        [self.bigScrollView setContentOffset:CGPointMake(WIDTH*4, 0) animated:YES];
    }
}


-(void)creatScrollView {
    //外层scrollview
    [self setAutomaticallyAdjustsScrollViewInsets:NO];
    self.bigScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 40, WIDTH, [[UIScreen mainScreen] bounds].size.height-40)];
    [self.view addSubview:self.bigScrollView];
    self.bigScrollView.contentSize = CGSizeMake(WIDTH*5, [[UIScreen mainScreen] bounds].size.height-40);
    self.bigScrollView.pagingEnabled = YES;
    self.bigScrollView.bounces = NO;
    self.bigScrollView.showsHorizontalScrollIndicator = NO;
    self.bigScrollView.showsVerticalScrollIndicator = NO;
    self.bigScrollView.delegate = self;
    
    
    VideoViewController * videoVC = [[VideoViewController alloc] init];
    [self addChildViewController:videoVC];
    videoVC.view.frame = CGRectMake(WIDTH, 0, WIDTH, HEIGHT);
    [self.bigScrollView addSubview:videoVC.view];
    
    SaiViewController * saiVC = [[SaiViewController alloc] init];
    [self addChildViewController:saiVC];
    saiVC.view.frame = CGRectMake(WIDTH*2, 0, WIDTH, HEIGHT);
    [self.bigScrollView addSubview:saiVC.view];
    
    PicViewController * picVC = [[PicViewController alloc] init];
    [self addChildViewController:picVC];
    picVC.view.frame = CGRectMake(WIDTH*3, 0, WIDTH, HEIGHT);

    [self.bigScrollView addSubview:picVC.view];
    PhotoViewController * phVC = [[PhotoViewController alloc] init];
    [self addChildViewController:phVC];
    phVC.view.frame = CGRectMake(WIDTH*4, 0, WIDTH, HEIGHT);

    [self.bigScrollView addSubview:phVC.view];
    
    TopViewController * topVC = [[TopViewController alloc] init];
    [self addChildViewController:topVC];
    [self.bigScrollView addSubview:topVC.view];

}
#pragma mark ---- UIScrollViewDelegate

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
    self.sliderView.frame = CGRectMake(self.bigScrollView.contentOffset.x/5 , self.topButton.frame.origin.y+self.topButton.frame.size.height, self.topButton.frame.size.width, 2);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
